package com.hulk.dryad.persistence.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hulk.dryad.common.annotation.Sensitive;
import com.hulk.dryad.common.constant.enums.RootFlag;
import com.hulk.dryad.common.jackson.sensitive.SensitiveTypeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author kim
 * @since 2017-10-29
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ToString(callSuper = true)
@TableName("t_sys_user")
public class SysUserModel extends SuperEntity<SysTenantModel> {

	private static final long serialVersionUID = 1L;

	/**
	 * 主键ID
	 */
	@TableId(value = "user_id", type = IdType.AUTO)
	private Long userId;

	/**
	 * 用户名
	 */
	private String username;

	/**
	 * 密码
	 */
	@Sensitive(type = SensitiveTypeEnum.PASSWORD)
	@ToString.Exclude
	private String password;

	/**
	 * 随机盐
	 */
	@ToString.Exclude
	@JsonIgnore
	private String salt;

	/**
	 * 创建时间
	 */
	@TableField(value = "created_time", fill = FieldFill.INSERT)
	private LocalDateTime createdTime;

	/**
	 * 修改时间
	 */
	@TableField(value = "updated_time", fill = FieldFill.INSERT_UPDATE)
	private LocalDateTime updatedTime;

	/**
	 * 0-正常，1-删除
	 */
	@TableLogic
	private String delFlag;

	/**
	 * 锁定标记 1-锁定/0-未锁定
	 */
	private String lockFlag;
	/**
	 * 1:离线 0:在线
	 */
	private String onlineFlag;

	/**
	 * 超级管理员标识
	 */
	private String rootFlag;

	/**
	 * 手机号
	 */
	private String phone;

	/**
	 * 头像
	 */
	@ToString.Exclude
	private String avatar;

	/**
	 * 部门ID
	 */
	private Integer deptId;

	/**
	 * TOTP
	 */
	@ToString.Exclude
	private String totp;

	/**
	 * TOEKN值
	 */
	@ToString.Exclude
	private String token;
	/**
	 * TOEKN过期时间
	 */
	private LocalDateTime tokenExpireTime;

	public boolean isRoot() {
		return RootFlag.ROOT.getValue().equals(rootFlag);
	}

}
